<?php

namespace app\xin\controller;

use app\xin\model\XBills;
use think\admin\helper\QueryHelper;
use think\admin\Controller;

/**
 * 版本管理
 * Class Admin
 * @package app\data\controller\user
 */
class Bills extends Controller
{
    /**
     * 版本列表管理
     * @auth true
     * @menu true
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        $this->type = $this->get['type'] ?? 'index';
        XBills::mQuery($this->get)->layTable(function () {
            $this->title = '版本列表管理';
        }, function (QueryHelper $query) {
            // 用户搜索查询
            $query->like('title')->dateBetween('addTime');
            //$query->where(['status' => intval($this->type === 'index'), 'deleted' => 0]);
        });
    }

    /**
     * 列表数据处理
     * @param array $data
     * @throws \Exception
     */
    protected function _index_page_filter(&$data)
    {
        if(!empty($data)){
            foreach ($data as $k=>$v){
                $type_name = 'ios';
                if($v['type'] == 2){
                    $type_name = 'android';
                }
                $data[$k]['type_name'] = $type_name;
            }
        }
    }

    public function add()
    {
        $this->title = '添加';
        XBills::mForm('form');
    }

    /**
     * 编辑反馈
     * @auth true
     */
    public function edit()
    {
        $this->title = '编辑';
        XBills::mForm('form');
    }

    /**
     * 表单处理
     * @param array $data
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    protected function _form_filter(&$data)
    {
        if ($this->request->isGet()) {

            $this->cates = [
                ['id'=>1,'name'=>'ios'],
                ['id'=>2,'name'=>'android']
            ];
        }else{
            //print_r($data);
            if(!isset($data['id'])){$data['addtime'] = date('Y-m-d H:i:s');}
        }
    }

    /**
     * 修改版本状态
     * @auth true
     */
    public function state()
    {
        XBills::mSave($this->_vali([
            'is_force.in:0,1'  => '状态值范围异常！',
            'is_force.require' => '状态值不能为空！',
        ]));
    }

    /**
     * 删除版本状态
     * @auth true
     */
    public function remove()
    {
        XBills::mDelete();
    }

}